class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n = nums.size();
        if(n == 0)return 0;
        int len = INT_MAX;
        int sum = 0;
        for(int l = 0,r = 0;r < n;r++){//外层循环往右扩展
            sum += nums[r];
            while(sum >= target){//内层循环调整左指针
                len = min(len,r-l+1);
                sum -= nums[l];
                l++;
            }
        }
        return len == INT_MAX ? 0 : len;   
    }
};